<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="zhangfn"
	uri="http://github.com/zhangkaitao/tags/zhang-functions"%>
<html>
<head>
<title></title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/static/css/css.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/static/JQuery zTree v3.5.15/css/zTreeStyle/zTreeStyle.css">
<style>
ul.ztree {
	margin-top: 10px;
	border: 1px solid #617775;
	background: #f0f6e4;
	width: 220px;
	height: 200px;
	overflow-y: scroll;
	overflow-x: auto;
}
</style>

</head>
<body>
	<h2>新闻管理</h2>
	<form:form method="post" commandName="news"
		enctype="multipart/form-data">
		<form:hidden path="id" />
		<form:hidden path="lang" />
		<form:hidden path="content" />
		
		<div class="form-group">
			<form:label path="name">名称：</form:label>
			<form:input path="name" />
		</div>

		<div class="form-group">
			<form:label path="content">文件路径：</form:label>
			<a href="${news.content}" target="_blank">PDF文件</a> 
			<input
				type="file" name=file>
		</div>
		<div class="form-group">
			<form:label path="code">新闻种类：</form:label>

			<form:select path="code" class="form-control">
				<form:option value="market_comments">市场动态</form:option>
				<form:option value="market_reports">市场焦点</form:option>
			</form:select>
		</div>

		<div class="form-group">
			<form:label path="remark">备注：</form:label>
			<form:input path="remark" />
		</div>

		<form:button>${op}</form:button>

	</form:form>


	<div id="menuContent" class="menuContent"
		style="display: none; position: absolute;">
		<ul id="tree" class="ztree" style="margin-top: 0; width: 160px;"></ul>
	</div>

	<script
		src="${pageContext.request.contextPath}/static/js/jquery-1.11.0.min.js"></script>
	<script
		src="${pageContext.request.contextPath}/static/JQuery zTree v3.5.15/js/jquery.ztree.all-3.5.min.js"></script>
	<script>
        $(function () {
            var setting = {
                check: {
                    enable: true ,
                    chkboxType: { "Y": "", "N": "" }
                },
                view: {
                    dblClickExpand: false
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                callback: {
                    onCheck: onCheck
                }
            };

            var zNodes =[
                <c:forEach items="${resourceList}" var="r">
                <c:if test="${not r.rootNode}">
                { id:${r.id}, pId:${r.parentId}, name:"${r.name}", checked:${zhangfn:in(role.resourceIds, r.id)}},
                </c:if>
                </c:forEach>
            ];

            function onCheck(e, treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj("tree"),
                        nodes = zTree.getCheckedNodes(true),
                        id = "",
                        name = "";
                nodes.sort(function compare(a,b){return a.id-b.id;});
                for (var i=0, l=nodes.length; i<l; i++) {
                    id += nodes[i].id + ",";
                    name += nodes[i].name + ",";
                }
                if (id.length > 0 ) id = id.substring(0, id.length-1);
                if (name.length > 0 ) name = name.substring(0, name.length-1);
                $("#resourceIds").val(id);
                $("#resourceName").val(name);
//                hideMenu();
            }

            function showMenu() {
                var cityObj = $("#resourceName");
                var cityOffset = $("#resourceName").offset();
                $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

                $("body").bind("mousedown", onBodyDown);
            }
            function hideMenu() {
                $("#menuContent").fadeOut("fast");
                $("body").unbind("mousedown", onBodyDown);
            }
            function onBodyDown(event) {
                if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
                    hideMenu();
                }
            }

            $.fn.zTree.init($("#tree"), setting, zNodes);
            $("#menuBtn").click(showMenu);
        });
    </script>


</body>
</html>